var app = getApp()

Page({
	data: {
		titel: ['全部', '待付款', '待入住'],
		page: 1,
		order_list: [],
		user_ids: 0
	},
	onLoad: function (t) {
		var e = this
		app.getUrl(e)
		var a = t.activeIndex,
			r = t.index
		e.setData({
			activeIndex: a,
			index: r,
			status: t.status || '0'
		}),
			e.refresh()
	},
	refresh: function (t) {
		var a = this,
			r = a.data.page,
			i = a.data.order_list,
			e = (a.data.index, app.globalData.userId)
		console.log(r, i, e, 'rie')
		a.setData({
			user_ids: e
		})
		app.today_time()
		app.util.request({
			// url: "entry/wxapp/MyOrder",
			url: 'order/orderList',
			cachetime: '0',
			data: {
				user_id: e,
				page: r,
				status: a.data.status
			},
			testapi: app.siteInfo.siteroot_web,
			success: function (t) {
				if (0 < t.data.data.data.length) {
					a.setData({
						page: r + 1
					}),
						(i = i.concat(t.data.data.data))
					// for (var e in i) i[e].arrival_time = i[e].arrival_time.slice(5, 7) + "月" + i[e].arrival_time.slice(8, 10) + "日",
					// i[e].departure_time = i[e].departure_time.slice(5, 7) + "月" + i[e].departure_time.slice(8, 10) + "日";
					a.setData({
						order_list: i
					})

					console.log(a.data.order_list, 'orderList')
				}
			}
		})
	},
	tabClick: function (t) {
		this.setData({
			activeIndex: t.currentTarget.dataset.index,
			index: t.currentTarget.dataset.index,
			status: t.currentTarget.dataset.state,
			page: 1,
			order_list: []
		}),
			this.refresh()
	},
	order_info: function (t) {
		var e = t.currentTarget.dataset.id
		var user_ids = this.data.user_ids
		wx.navigateTo({
			// url: "orderinfo?id=" + e
			url: 'infoOrder?id=' + e + '&user_ids=' + user_ids
		})
	},
	onReady: function () {},
	onShow: function () {
		this.setData({
			index: 0,
			activeIndex: 0,
			page: 1,
			order_list: []
		}),
			this.refresh()
		this.setTabBarSelected()
	},
	/**
	 * @function 设置自定义tabbar选中状态
	 */
	setTabBarSelected() {
		if (typeof this.getTabBar === 'function') {
			this.getTabBar(tabBar => {
				tabBar.setData({
					selected: 1
				})
			})
		}
	},
	onPullDownRefresh: function () {
		this.setData({
			index: 0,
			page: 1,
			order_list: []
		}),
			this.refresh(),
			wx.stopPullDownRefresh()
	},
	onReachBottom: function () {
		this.refresh()
	},
	onShareAppMessage: function () {}
})
